# 第一题作业
# 定义类属性，实现自动增长
print('第一题作业：')
print('=='*40)

class Student(object):
    count = 0

    def __init__(self, name, score):
        self.__name = name
        self.__score = score
        Student.count += 1

class_python22 = ['xiaohong', 'xiaoming', 'xiaoli', 'xiaos']
for stu in class_python22:
    students = Student(stu, 0)

print('班级学生有：%s' % class_python22)
print('总共学生数为：%d' % Student.count)
print('=='*40)

# 第二题作业
# 设计装饰器，打印函数的运行时间
print('第二题作业：')
print('=='*40)
import time
import functools

def ex_fun_time(fn):
    @functools.wraps(fn)
    def metric(*args, **kw):
        start_time = time.time()
        end_time = time.time()
        print('{} 函数运行耗时：{:.4f}'.format(fn.__name__, end_time - start_time))
        return fn(*args, **kw)
    return metric

@ex_fun_time
def mul(x, y):
    return x*y

mul(3, 5)

@ex_fun_time
def add(x, y):
    total = 0
    for i in range(x, y):
        total += i

add(1, 100)
print('=='*40)
